﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class USupplerPartDAL
    {
        public static int AddInput( USupplerPartInfo obj ,string Remark)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("USupplerPart_AddInput", obj.ItemCode, obj.ItemName, obj.StockQuantity, obj.SupplerName, Remark);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(string ItemCode)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("USupplerPart_Delete", ItemCode);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetByItemCode(string ItemCode)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("USupplerPart_GetByItemCode", ItemCode);
            return DB.ExecuteReader(dbCommand);
	    }
        public static DataTable GetDetailByItemCode(string ItemCode)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("USupplerPart_GetDetailByItemCode", ItemCode);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
	    }
        public static DataTable GetPagination(string ItemCode,string SupplerName, int PageIndex, int PageSize, string Sort, ref int TotalCount)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("USupplerPart_GetPagination");
            DB.AddInParameter(dbCommand, "ItemCode", DbType.String,ItemCode);
            DB.AddInParameter(dbCommand, "SupplerName", DbType.String, SupplerName);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32,PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32,PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String,Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32,8);
		    DataTable dt=  DB.ExecuteDataSet(dbCommand).Tables[0];
				
            TotalCount=Convert.ToInt32( DB.GetParameterValue(dbCommand,"TotalCount"));
            return dt;
	    }
    }
}
